package cn.xxxy.fourm.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.xxxy.fourm.dao.ReplyPostDao;
import cn.xxxy.fourm.entity.Post;
import cn.xxxy.fourm.entity.ReplyPost;
import cn.xxxy.fourm.model.ReplyPostDto;
import cn.xxxy.fourm.service.ReplyPostService;

@Service@Transactional
public class ReplyPostServiceImpl implements ReplyPostService{
	@Autowired
	private ReplyPostDao replyPostDao;

	@Override
	public List<ReplyPostDto> listMyRePostsByUid(int uid) {
		List<ReplyPostDto> replyPostDto=new ArrayList<>();
		List<ReplyPost> replyPosts=replyPostDao.findByUId(uid);
		for (ReplyPost replyPost : replyPosts) {
			ReplyPostDto rpd=new ReplyPostDto();
			rpd.setAdopt(replyPost.getAdopt());		
			rpd.setPid(replyPost.getPost().getPid());
			rpd.setRcontent(replyPost.getRcontent());
			rpd.setPtitle(replyPost.getPost().getPtitle());
			rpd.setReplytime(replyPost.getReplytime());
			rpd.setUid(replyPost.getUser().getUid());
			rpd.setUname(replyPost.getUser().getUname());
			replyPostDto.add(rpd);
		}
		return replyPostDto;
	}

	@Override
	public List<ReplyPostDto> listRePostsByUid(int uid) {
		List<ReplyPostDto> replyPostDto=new ArrayList<>();
		List<ReplyPost> list= replyPostDao.findMyAllReply(uid);
		for (ReplyPost replyPost : list) {
			ReplyPostDto rpd=new ReplyPostDto();
			rpd.setAdopt(replyPost.getAdopt());		
			rpd.setPid(replyPost.getPost().getPid());
			rpd.setRcontent(replyPost.getRcontent());
			rpd.setPtitle(replyPost.getPost().getPtitle());
			rpd.setReplytime(replyPost.getReplytime());
			rpd.setUid(replyPost.getUser().getUid());
			rpd.setUname(replyPost.getUser().getUname());
			replyPostDto.add(rpd);
		}
		return replyPostDto;
	}
	
}
